package com.stgl.action;

import com.alibaba.fastjson.JSONArray;
import com.stgl.service.BmqkService;
import net.sf.jxls.exception.ParsePropertyException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.SimpleDateFormat;
import com.stgl.util.ExportExcel;
import java.util.*;

@Controller
@RequestMapping("/bmqk")
public class bmqk {
    @Resource
    private BmqkService bmqkService;

    @RequestMapping("Search_bmqkNow.html")
    @ResponseBody
    public Map<String,Object>Search_bmqkNow(HttpServletRequest request, HttpServletResponse response){
        String nj=request.getParameter("nj").trim();
        String bj=request.getParameter("bj").trim();

        String km="";
        if(request.getParameter("km")!=null){
            km=request.getParameter("km").trim();
        }
        String mc="";
        if(request.getParameter("mc")!=null){
            mc=request.getParameter("mc").trim();
        }
        String bmlb="";
        if(request.getParameter("bmlb")!=null){
            bmlb=request.getParameter("bmlb").trim();
        }
        String shqk=request.getParameter("shqk").trim();
        String wstate=request.getParameter("wstate").trim();

        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("nj",nj);
        gmap.put("bj",bj);
        gmap.put("km",km);
        gmap.put("mc",mc);
        gmap.put("shqk",shqk);
        gmap.put("wstate",wstate);
        gmap.put("bmlb",bmlb);
        gmap.put("bstate","0");
        gmap.put("sstate","0");
        HttpSession session=((HttpServletRequest)request).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=bmqkService.Search_bmqkNow(gmap);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("data",list1);
        return rmap;
    }



    @RequestMapping("Search_bmqkNowByid.html")
    @ResponseBody
    public Map<String,Object>Search_bmqkNowByid(HttpServletRequest request, HttpServletResponse response){
        if(request.getParameter("wsid")==null){
            return new HashMap<String,Object>();
        }
        String shqk=request.getParameter("shqk").trim();
        String wsid=request.getParameter("wsid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("shqk",shqk);
        gmap.put("wsid",wsid);
        if(wsid.equals("")){
            return new HashMap<String,Object>();
        }
        List<Map<String,Object>>list1=bmqkService.Search_bmqkNow(gmap);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("data",list1);
        return rmap;
    }



    @RequestMapping("bmqk_sh.html")
    @ResponseBody
    public Boolean bmqk_sh(HttpServletRequest request, HttpServletResponse response){
        String bid=request.getParameter("bid").trim();
        String shqk=request.getParameter("shqk").trim();

        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("bid",bid);
        gmap.put("shqk",shqk);

        int i=bmqkService.bmqk_sh(gmap);
        if(i>=0){
            return true;
        }
        return false;
    }







    @RequestMapping("Search_sthdbmqkNow.html")
    @ResponseBody
    public Map<String,Object>Search_sthdbmqkNow(HttpServletRequest request, HttpServletResponse response){
        String mc=request.getParameter("mc").trim();
        String shqk=request.getParameter("shqk").trim();
        String sstate=request.getParameter("sstate").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("mc",mc);
        gmap.put("shqk",shqk);
        gmap.put("sstate",sstate);
        HttpSession session=((HttpServletRequest)request).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=bmqkService.Search_sthdbmqkNow(gmap);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("data",list1);
        return rmap;
    }





    @RequestMapping("Search_sthdbmqkNowByid.html")
    @ResponseBody
    public Map<String,Object>Search_sthdbmqkNowByid(HttpServletRequest request, HttpServletResponse response){
        String shqk=request.getParameter("shqk").trim();
        String wsid=request.getParameter("wsid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("shqk",shqk);
        gmap.put("wsid",wsid);

        List<Map<String,Object>>list1=bmqkService.Search_sthdbmqkNow(gmap);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("data",list1);
        return rmap;
    }





    /**辅导班报名导出**/
    @RequestMapping("/export_bmqkNow.html")
    @ResponseBody
    public void export_bmqkNow(HttpServletRequest req, HttpServletResponse res) throws ParsePropertyException, IOException, InvalidFormatException, IllegalAccessException {
        String nj=req.getParameter("nj").trim();
        String bj=req.getParameter("bj").trim();
        String km="";
        if(req.getParameter("km")!=null){
            km=req.getParameter("km").trim();
        }
        String mc="";
        if(req.getParameter("mc")!=null){
            mc=req.getParameter("mc").trim();
        }
        String bmlb="";
        if(req.getParameter("bmlb")!=null){
            bmlb=req.getParameter("bmlb").trim();
        }
        String shqk=req.getParameter("shqk").trim();
        String wstate=req.getParameter("wstate").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("nj",nj);
        gmap.put("bj",bj);
        gmap.put("km",km);
        gmap.put("mc",mc);
        gmap.put("shqk",shqk);
        gmap.put("wstate",wstate);
        gmap.put("bmlb",bmlb);
        gmap.put("bstate","0");
        gmap.put("sstate","0");
        HttpSession session=((HttpServletRequest)req).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=bmqkService.export_bmqkNow(gmap);
        Map<String,Object>resultm=new HashMap<String,Object>();
        resultm.put("list1",list1);
        /*****...................................获取数据end..............................******/
        String modalxls="exportBmqk.xlsx";

        ExportExcel.download(modalxls,resultm,req,res);

        return;
    }




    /**活动辅导班报名导出**/
    @RequestMapping("/export_sthdbmqkNow.html")
    @ResponseBody
    public void export_sthdbmqkNow(HttpServletRequest req, HttpServletResponse res) throws ParsePropertyException, IOException, InvalidFormatException, IllegalAccessException {
        String mc=req.getParameter("mc").trim();
        String shqk=req.getParameter("shqk").trim();
        String sstate=req.getParameter("sstate").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("mc",mc);
        gmap.put("shqk",shqk);
        gmap.put("sstate",sstate);
        HttpSession session=((HttpServletRequest)req).getSession();
        if(session.getAttribute("csid")!=null){
            String csid=session.getAttribute("csid").toString();
            gmap.put("csid",csid);
        }
        List<Map<String,Object>>list1=bmqkService.export_sthdbmqkNow(gmap);
        Map<String,Object>resultm=new HashMap<String,Object>();
        resultm.put("list1",list1);
        /*****...................................获取数据end..............................******/
        String modalxls="exportStqkBmqk.xlsx";

        ExportExcel.download(modalxls,resultm,req,res);

        return;
    }



    @RequestMapping("setjffs.html")
    @ResponseBody
    public int setjffs(HttpServletRequest request, HttpServletResponse response){
        String jffs=request.getParameter("jffs").trim();
        String oid=request.getParameter("oid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("jffs",jffs);
        gmap.put("oid",oid);
        int i=bmqkService.setjffs(gmap);
        return i;
    }

    @RequestMapping("del_bmqkBybid.html")
    @ResponseBody
    public Map<String,Object> del_bmqkBybid(HttpServletRequest request, HttpServletResponse response){
        String bid=request.getParameter("bid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("bid",bid);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap=bmqkService.del_bmqkBybid(gmap);
        return rmap;
    }


    /**辅导班报名导出**/
    @RequestMapping("/export_bmqkNowByid.html")
    @ResponseBody
    public void export_bmqkNowByid(HttpServletRequest req, HttpServletResponse res) throws ParsePropertyException, IOException, InvalidFormatException, IllegalAccessException {

        String shqk=req.getParameter("shqk").trim();
        String wsid=req.getParameter("wsid").trim();
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("shqk",shqk);
        gmap.put("wsid",wsid);

        List<Map<String,Object>>list1=bmqkService.Search_bmqkNow(gmap);
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("data",list1);

        Map<String,Object>resultm=new HashMap<String,Object>();
        resultm.put("list1",list1);
        /*****...................................获取数据end..............................******/
        String modalxls="exportBmqk.xlsx";

        ExportExcel.download(modalxls,resultm,req,res);
    }




    //学生调班
    @RequestMapping("changStudentBmqk.html")
    @ResponseBody
    public boolean resHistoryWhkfdb(HttpServletRequest request, HttpServletResponse response){
        String bid=request.getParameter("bid").trim();//报名情况id
        String wsid=request.getParameter("wsid").trim();//学生需要报名的班级
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("bid",bid);
        gmap.put("wsid",wsid);
        //1.修改学生需要报的报名
        int i=bmqkService.updateStuBmqk(gmap);

        if(i>0){
            //2修改orderlist
            int j= bmqkService.updateOrderListByBid(gmap);
            if(j>0){
                //3修改ordertea
                bmqkService.updateOrderTeaByWsid(gmap);
            }
        }else{
            return false;
        }
        return true;
    }


}
